<template>
	<view class="home">
		<view v-if="!xzqhszDm">
			<view class="cityChoice">
				<view class="tip">请选择所属行政区</view>
					<view class="selectXlk">
						<picker @change="xzqChange" :value="xzqIndex" :range="xzqArrMc">
							<view>{{xzqArrMc[xzqIndex]}}</view>
						</picker>
				    </view>
				<button type="primary" class="qrbtn" size="mini" @click="qrxzqChoice">确定</button>
			</view>
		</view>
		 <view v-else>
			<view class="tp lc">
				<image src="../../static/header.png" mode="scaleToFill">
					<view class="name">个人出租屋税费业务办理</view>
			</view>
			<view class="tp bj">
				<image src="../../static/bg.jpg" mode="scaleToFill">
			</view>
			<view class="text-area" v-for="(item,i) in navArray" :key="i" v-if="item.xzqhszDm.includes(xzqhszDm)">
				<!-- <navigator :url="item.url+'?backUrl=/pages/index/index'"> -->
				<view class="navItem" @click="tzNav(item.url)">
					<text :class="item.icon"></text>
					<text>{{item.name}}</text>
				</view>
				<!-- </navigator> -->
			</view>
		</view>
		<znzx :openId="openId"></znzx>
	</view>
</template>

<script>
	import {
		login
	} from "@/utils/common-api.js"
	import commonTools from "@/utils/common-tools.js";
    import znzx from "@/pages/znzx/znzx.vue"
	export default {
		data() {
			return {
				tip: "",
				title: 'Hello',
				navArray: [{
						name: "税费申报",
						url: "/pages/sfsb/sbzr",
						icon: "iconfont icon-tijiaochenggong iconcg",
						xzqhszDm:["440100","440600"]
					},
					{
						name: "城镇土地使用税申报",
						url: "/pages/cztdsyssb/yxfycx",
						icon: "iconfont icon-sousuowenjian",
						xzqhszDm:["440600"]
					},
					{
						name: "税费清缴",
						url: "/pages/sfqj/dqj",
						icon: "iconfont icon-sousuowenjian",
						xzqhszDm:["440100","440600"]
					},
					{
						name: "税收完税证明",
						url: "/pages/sswszm/sswszm",
						icon: "iconfont icon-sousuowenjian",
						xzqhszDm:["440100","440600"]
					},
					{
						name: "发票查询",
						url: "/pages/dzfp/index",
						icon: "iconfont icon-sousuowenjian",
						xzqhszDm:["440600"]
					},
					{
						name: "申请代开增值税电子普通发票",
						url: "/pages/sqdkfp/index",
						icon: "iconfont icon-sousuowenjian",
						xzqhszDm:["440100"]
					},
					{
						name: "代开发票查询",
						url: "/pages/dkfpcx/index",
						icon: "iconfont icon-sousuowenjian",
						xzqhszDm:["440100"]
					},
					{
						name: "代开发票授权",
						url: "/pages/dkfpsq/index",
						icon: "iconfont icon-sousuowenjian",
						xzqhszDm:["440100"]
                    },
					{
						name: "申报缴款明细查询",
						url: "/pages/sbcx/index",
						icon: "iconfont icon-sousuowenjian ",
						xzqhszDm:["440100","440600"]
					}
				],
				DZSWJ_TGC: "",
				openId:"",
				xzqhszDm:"",
				xzqhmc:"",
				xzqArrMc:["请选择","广州市","佛山市"],
				xzqArrDm:["","440100","440600"],
				xzqIndex:0,
				zjhm:"",
				xm:"",
			}
		},
		components: {
			znzx
		},
		onLoad(e) {
			// 获取粤税通登录身份
			if (e.DZSWJ_TGC) {
				this.DZSWJ_TGC = e.DZSWJ_TGC
				this.openId=e.openId
				console.log("出租屋", e)
				commonTools.setDZSWJ_TGC(this.DZSWJ_TGC)
			}
			// 自定义登录
			this.zjhm=e.zjhm
			this.xm=e.xm
		},
		async onShow() {
			this.qchc()
		},
		methods: {
			// 行政区选择
			xzqChange(e){
				console.log(e)
				this.xzqIndex = e.detail.value
				
			},
			// 行政区选择确定
		    async qrxzqChoice(){
				commonTools.setXzq({})
				this.xzqhszDm=this.xzqArrDm[this.xzqIndex]
				this.xzqhmc=this.xzqArrMc[this.xzqIndex]
				if(!this.xzqhszDm){
					uni.showToast({
						title: '请选择所属行政区',
						icon: 'error',
						duration: 1000
					});
					return
				}
				commonTools.setXzq({xzqhszDm:this.xzqhszDm,xzqhmc:this.xzqhmc})
			    await this.jxLogin()
			},
			//登录接口
			async jxLogin() {
				commonTools.setUserToken("")
				commonTools.setUserInfo({})
				var lists = ""
				// process.env.NODE_ENV
				if (process.env.ENV_TYPE === 'dev' || process.env.ENV_TYPE === 'test') {
					// 开发环境
					// lists = await login({
					// 	zjhm: "450924199909234111",
					// 	zjlx: "201",
					// 	xm: "11",
					// 	xzqhszDm:this.xzqhszDm,
					// 	xzqhmc:this.xzqhmc
					// }) 
					// lists = await login({
					// 	zjhm: "45042219890728054X",
					// 	zjlx: "201",  
					// 	xm: "朱泳梅"
					// })
					lists = await login({
						zjhm: "432522199103082474",
						zjlx: "201",
						xm: "罗亚东",
						xzqhszDm:this.xzqhszDm,
						xzqhmc:this.xzqhmc
					})
					// 佛山发票测试
					// lists = await login({
					// 	zjhm: "440622194501150017",
					// 	zjlx: "201",
					// 	xm: "自然人267349",
					// 		xzqhszDm:this.xzqhszDm,
					// 		xzqhmc:this.xzqhmc
					// })

					// 佛山蔡金莲测试
					// lists = await login({
					// 	zjhm: "440882198811131925",
					// 	zjlx: "201",
					// 	xm: "蔡金莲",
					// 		xzqhszDm:this.xzqhszDm,
					// 		xzqhmc:this.xzqhmc
					// })
					// 自定义登录测试
					// lists = await login({
					// 	zjhm: this.zjhm,
					// 	zjlx: "201",
					// 	xm: this.xm,
					// 	xzqhszDm:this.xzqhszDm,
					// 	xzqhmc:this.xzqhmc
					// })
				} else {
					// 生产环境
					lists = await login({xzqhszDm:this.xzqhszDm,xzqhmc:this.xzqhmc})
				}
				// console.log(lists)
				if (lists.head.errorCode == "0" && lists.body) {
					commonTools.setUserToken(lists.body.token)
					commonTools.setUserInfo(lists.body)
				} else if (lists.head.errorCode == "99998") {
					uni.showModal({
						title: '提示',
						content: '当前登录所用证件没有查询到对应的房屋租赁信息，请确认是否已在出租屋管理部门采集租赁信息，或登录所用证件是否与采集的租赁信息一致',
						confirmColor: '#000000', //确定字体颜色
						showCancel: false, //没有取消按钮的弹框 
						buttonText: '确定',
						success: function(res) {
							if (res.confirm) {
								wx.miniProgram.navigateBack();
							}
						}
					});
				} else {
					uni.showModal({
						title: '提示',
						content: '数据请求错误：' + lists.head.errorMsg + "！",
						confirmColor: '#000000', //确定字体颜色
						showCancel: false, //没有取消按钮的弹框 
						buttonText: '确定',
						success: function(res) {
							if (res.confirm) {
								wx.miniProgram.navigateBack();
							}
						}
					});
				}
			},
			// 路由跳转
			tzNav(val) {
				this.$commonCzwjs.goPage({
					url: val
				})
			},
			// 清除缓存
			qchc() {
				uni.removeStorageSync('dqjcxData');
				uni.removeStorageSync('dqjData');
			},
		}
	}
</script>

<style>
	.home {
		height: 100vh;
	}
	.cityChoice{
		padding: 60rpx 20rpx;
		box-sizing: border-box;
		width: calc(100% - 20rpx);
		position: absolute;
		top: 0;
		/* transform: translateY(-50%); */
		background: #ffffff;
		border: 1px #00000030 solid;
		margin: 10rpx;
	}
	.cityChoice > .tip{
		color: #0000ffcc;
	}
	.selectXlk {
		margin: 20rpx 0;
		padding: 0 20rpx;
		height: 70rpx;
		line-height: 70rpx;
		width: 100%;
		font-size: 28rpx;
		color: #666;
		border: 1px #e5e5e5 solid;
		border-radius: 10rpx;
		box-sizing: border-box;
		font-size: 28rpx;
		overflow: hidden;
	}
	.cityChoice> uni-button {
		width: 100%;
		height: 70rpx;
		line-height: 70rpx;
	}

	.navItem {
		position: relative;
	}

	.tp {
		width: 100%;
		height: 360rpx;
	}

	.lc {
		position: relative;
		z-index: 100;
	}

	.bj {
		position: absolute;
		top: 0;
		left: 0;
		z-index: 50;

	}

	.name {
		position: absolute;
		top: 50rpx;
		color: #ffffff;
		font-size: 40rpx;
		width: 100%;
		text-align: center;
	}

	image {
		width: 100%;
		height: 100%;
	}

	.text-area {
		width: 100%;
		display: flex;
		justify-content: center;
		margin-top: 40rpx;
	}

	.navItem {
		width: 600rpx;
		height: 70rpx;
		text-align: center;
		line-height: 70rpx;
		border: 2rpx solid #2e9cf2;
		color: #2e9cf2;
		border-radius: 6rpx;
		font-size: 28rpx;
		/* font-weight: bold; */
		letter-spacing: 4rpx;
		position: relative;
	}

	.iconfont {
		position: absolute;
		left: 20rpx;
	}

	.iconcg {
		font-size: 42rpx;
		left: 16rpx;
	}

</style>